//package com.extract.config;
//
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Primary;
//import org.springframework.scheduling.annotation.AsyncConfigurer;
//import org.springframework.scheduling.annotation.EnableAsync;
//import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
//
//import java.util.concurrent.Executor;
//import java.util.concurrent.ThreadPoolExecutor;
//
//@Slf4j
//@Configuration
//@EnableAsync
//public class AsyncThreadPool implements AsyncConfigurer {
//
//    @Primary
//    @Override
//    @Bean(name = "asyncExecutor")
//    public Executor getAsyncExecutor() {
//        ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
//        // 默认值是1
//        int cpuNum = Runtime.getRuntime().availableProcessors();
//        taskExecutor.setCorePoolSize(cpuNum);
//        // 默认值是Integer.MAX_VALUE
//        taskExecutor.setMaxPoolSize(8 * cpuNum + 1);
//        taskExecutor.setThreadNamePrefix("task-pool->");
//        // 默认值是60s
//        taskExecutor.setKeepAliveSeconds(90);
//        // 默认值是Integer.MAX_VALUE
//        taskExecutor.setQueueCapacity(2048);
//        // CallerRunsPolicy：不在新线程中执行任务，而是有调用者所在的线程来执行
//        taskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
//        taskExecutor.initialize();
//        log.info("自定义[ctm-pool]线程池初始化完成，核心线程数量：{}，最大线程数量：{}，队列容量：{}", cpuNum, 4 * cpuNum + 1, 2048);
//        return taskExecutor;
//    }
//
//    /**
//     * 异步执行异常处理器
//     */
//    @Override
//    public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
//        return (throwable, method, args) -> log.error("Exception happened during the thread executing,error message:{}", throwable.getMessage());
//    }
//}
